version 13
#delimit;
clear all;
set more off;
capture log close;


global strformat "%8.3f";

capture program drop sig_p;
program sig_p;
   args obj_var point_est_var point_sd_var p_val row_id_var row_num;
   local point_est `point_est_var';
   local point_sd `point_sd_var';
   if `p_val' > 0.1 {;
      replace `obj_var' = string(`point_est', "$strformat") if `row_id_var' == `row_num';
      };
   if `p_val' > 0.05 & `p_val' <= 0.1  {;
      replace `obj_var' = string(`point_est', "$strformat")+"*" if `row_id_var' == `row_num';
      };
   if `p_val' > 0.01 & `p_val' <= 0.05  {;
      replace `obj_var' = string(`point_est', "$strformat")+"**" if `row_id_var' == `row_num';
      };
   if `p_val' <= 0.01 {;
      replace `obj_var' = string(`point_est', "$strformat")+"***" if `row_id_var' == `row_num';
      };
   replace `obj_var' = "<" + string(`point_sd', "$strformat") + ">" + " " if `row_id_var' == `row_num' + 1;
   end;


*enter directory name here;

use "$dir/ReStat_children.dta", clear;



drop if pooled_treatment == 0 & school_type_pprs == 1;
generate row_num = _n;


generate included_school = 1 if 
	school_type_pprs == 1 | school_type_govt == 1 | school_type_private == 1;

forvalues i=0/25 {;
	generate col`i' = "";
};

local row = 5;
sort row_num;
order col0-col25;

replace col2 = "pprs" if row_num == 3;
replace col3 = "pprs -" if row_num == 2;
replace col3 = "govt" if row_num == 3;

replace col8 = "pprs" if row_num == 3;
replace col9 = "pprs -" if row_num == 2;
replace col9 = "govt" if row_num == 3;



foreach var of varlist 
	ss2_num_days_operational ss2_open_admission ss6_uniform_required ss6_school_tuition_required ss2_language_sindhi ss2_language_english {;
	
	replace col0 = "`var'" if row_num == `row';

	su `var' if child_school_level == 1 & fu_young_child == 1 & school_type_pprs == 1 [aw=hh_weight];
	replace col2 = string(r(mean), "$strformat") if row_num == `row';
	replace col2 = "<" + string(r(sd), "$strformat") + ">" if row_num == `row' + 1;
	
	local row = `row' + 2;
};


local row = 5;

foreach var of varlist 
	ss2_num_days_operational ss2_open_admission ss6_uniform_required {;
	

	regress `var' school_type_govt 
		if child_school_level == 1 & fu_young_child == 1 &
		(school_type_govt == 1 | school_type_pprs == 1) [iw=hh_weight];	
	est sto i_`row';
	
	local row = `row' + 2;
};

regress ss6_school_tuition_required school_type_govt 
	if child_school_level == 1 & fu_young_child == 1 &
	(school_type_govt == 1 | school_type_pprs == 1) [pw=hh_weight], cluster(villcode);	
test school_type_govt;
sig_p col3 _b[school_type_govt] _se[school_type_govt] r(p) row_num `row';


local row = `row' + 2;

foreach var of varlist 
	ss2_language_sindhi ss2_language_english {;
	

	regress `var' school_type_govt 
		if child_school_level == 1 & fu_young_child == 1 &
		(school_type_govt == 1 | school_type_pprs == 1) [iw=hh_weight];	
	est sto i_`row';
	
	local row = `row' + 2;
};


local row = `row' + 1;


gen pct_teachers_female = ss3_num_teachers_female/ss3_num_teachers;
gen pct_teachers_postsecondary = ss3_num_teachers_postsecondary/ss3_num_teachers;
gen pct_teachers_5years = ss3_num_teachers_5years/ss3_num_teachers;
gen pct_teachers_5to10years = ss3_num_teachers_5to10years/ss3_num_teachers;
gen pct_teachers_10years = ss3_num_teachers_10years/ss3_num_teachers;



foreach var of varlist 
	ss3_num_teachers 
	pct_teachers_female
	pct_teachers_postsecondary
	pct_teachers_5years
	pct_teachers_5to10years
	pct_teachers_10years
	ss3_avg_absent_2more {;
	
	replace col0 = "`var'" if row_num == `row';

	su `var' if child_school_level == 1 & fu_young_child == 1 & school_type_pprs == 1 [aw=hh_weight];
	replace col2 = string(r(mean), "$strformat") if row_num == `row';
	replace col2 = "<" + string(r(sd), "$strformat") + ">" if row_num == `row' + 1;
	
	regress `var' school_type_govt 
		if child_school_level == 1 & fu_young_child == 1 &
		(school_type_govt == 1 | school_type_pprs == 1) [iw=hh_weight];	
	est sto i_`row';

	
	local row = `row' + 2;
};


local row = `row' + 1;



foreach var of varlist 
	ss4_* {;
	
	replace col0 = "`var'" if row_num == `row';
	
	su `var' if child_school_level == 1 & fu_young_child == 1 & school_type_pprs == 1 [aw=hh_weight];
	replace col2 = string(r(mean), "$strformat") if row_num == `row';
	replace col2 = "<" + string(r(sd), "$strformat") + ">" if row_num == `row' + 1;
	
	regress `var' school_type_govt 
		if child_school_level == 1 & fu_young_child == 1 &
		(school_type_govt == 1 | school_type_pprs == 1) [iw=hh_weight];	
	est sto i_`row';

	local row = `row' + 2;
};

local row = 5;


generate student_teacher_ratio = (ss5_num_boys + ss5_num_girls)/ss3_num_teachers;

foreach var of varlist 
	ss5_num_boys ss5_num_girls ss5_pct_students_female student_teacher_ratio {;
	
	replace col6 = "`var'" if row_num == `row';
	
	su `var' if child_school_level == 1 & fu_young_child == 1 & school_type_pprs == 1 [aw=hh_weight];
	replace col8 = string(r(mean), "$strformat") if row_num == `row';
	replace col8 = "<" + string(r(sd), "$strformat") + ">" if row_num == `row' + 1;
	
	regress `var' school_type_govt 
		if child_school_level == 1 & fu_young_child == 1 &
		(school_type_govt == 1 | school_type_pprs == 1) [iw=hh_weight];	
	est sto ib_`row';
	
	local row = `row' + 2;
};

local row = `row' + 1;



foreach var of varlist 
	ss9_days_absent ss9_female
	ss9_age ss9_education ss9_monthly_salary ss9_years_teaching
	ss9_years_teaching_thischool {;
	
	replace col6 = "`var'" if row_num == `row';

	su `var' if child_school_level == 1 & fu_young_child == 1 & school_type_pprs == 1 [aw=hh_weight];
	replace col8 = string(r(mean), "$strformat") if row_num == `row';
	replace col8 = "<" + string(r(sd), "$strformat") + ">" if row_num == `row' + 1;
	
	regress `var' school_type_govt 
		if child_school_level == 1 & fu_young_child == 1 &
		(school_type_govt == 1 | school_type_pprs == 1) [iw=hh_weight];	
	est sto ib_`row';
	
	local row = `row' + 2;
};


local row = `row' + 1;



foreach var of varlist 
	ss9_hours_teaching ss9_hrs_teaching_wholeclass ss9_hrs_teaching_smallgroup
	ss9_hrs_teaching_individual ss9_hrs_teaching_notes ss9_hrs_teaching_discipline
	ss9_hrs_teaching_testing ss9_hrs_teaching_admin  {;
	
	replace col6 = "`var'" if row_num == `row';

	su `var' if child_school_level == 1 & fu_young_child == 1 & school_type_pprs == 1 [aw=hh_weight];
	replace col8 = string(r(mean), "$strformat") if row_num == `row';
	replace col8 = "<" + string(r(sd), "$strformat") + ">" if row_num == `row' + 1;
	
	regress `var' school_type_govt 
		if child_school_level == 1 & fu_young_child == 1 &
		(school_type_govt == 1 | school_type_pprs == 1) [iw=hh_weight];	
	est sto ib_`row';
	

	local row = `row' + 2;
};


suest i_* ib_*, cluster(villcode);


local row = 5;


foreach var of varlist 
	ss2_num_days_operational ss2_open_admission ss6_uniform_required {;
	
	test [i_`row'_mean]school_type_govt;
	sig_p col3 _b[i_`row'_mean:school_type_govt] _se[i_`row'_mean:school_type_govt] r(p) row_num `row';
	
	local row = `row' + 2;
	
};

local row = `row' + 2;

foreach var of varlist 
	ss2_language_sindhi ss2_language_english {;
	
	test [i_`row'_mean]school_type_govt;
	sig_p col3 _b[i_`row'_mean:school_type_govt] _se[i_`row'_mean:school_type_govt] r(p) row_num `row';
	
	local row = `row' + 2;
	
};


local row = `row' + 1;


foreach var of varlist 
	ss3_num_teachers 
	pct_teachers_female
	pct_teachers_postsecondary
	pct_teachers_5years
	pct_teachers_5to10years
	pct_teachers_10years
	ss3_avg_absent_2more {;
	
	test [i_`row'_mean]school_type_govt;
	sig_p col3 _b[i_`row'_mean:school_type_govt] _se[i_`row'_mean:school_type_govt] r(p) row_num `row';
	
	local row = `row' + 2;

};


local row = `row' + 1;



foreach var of varlist 
	ss4_* {;

	test [i_`row'_mean]school_type_govt;
	sig_p col3 _b[i_`row'_mean:school_type_govt] _se[i_`row'_mean:school_type_govt] r(p) row_num `row';
	
	local row = `row' + 2;

};


local row = 5;



foreach var of varlist 
	ss5_num_boys ss5_num_girls ss5_pct_students_female student_teacher_ratio {;
	
	test [ib_`row'_mean]school_type_govt;
	sig_p col9 _b[ib_`row'_mean:school_type_govt] _se[ib_`row'_mean:school_type_govt] r(p) row_num `row';
	
	local row = `row' + 2;
	
};


local row = `row' + 1;



foreach var of varlist 
	ss9_days_absent ss9_female
	ss9_age ss9_education ss9_monthly_salary ss9_years_teaching
	ss9_years_teaching_thischool {;
	
	test [ib_`row'_mean]school_type_govt;
	sig_p col9 _b[ib_`row'_mean:school_type_govt] _se[ib_`row'_mean:school_type_govt] r(p) row_num `row';
	
	local row = `row' + 2;

};


local row = `row' + 1;



foreach var of varlist 
	ss9_hours_teaching ss9_hrs_teaching_wholeclass ss9_hrs_teaching_smallgroup
	ss9_hrs_teaching_individual ss9_hrs_teaching_notes ss9_hrs_teaching_discipline
	ss9_hrs_teaching_testing ss9_hrs_teaching_admin  {;
	
	test [ib_`row'_mean]school_type_govt;
	sig_p col9 _b[ib_`row'_mean:school_type_govt] _se[ib_`row'_mean:school_type_govt] r(p) row_num `row';
	
	local row = `row' + 2;

};




local row = `row' + 13;

outsheet col0-col10 using "$dir/Table 8 School Char By Type Govt (SUR).csv"
	if row_num < `row', comma replace;
